/*
 * Created by JFormDesigner on Sat Dec 24 17:58:54 ICT 2011
 */

package View;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.sql.Date;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.TableModel;

import Entity.Employee;

public class EmployeeManageView extends JPanel {

	private static final long serialVersionUID = 1L;
	public EmployeeManageView() {
		initComponents();
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		scrollPane1 = new JScrollPane();
		tblListEmployee = new JTable();
		panel1 = new JPanel();
		s = new JLabel();
		txtEmpNumber = new JTextField();
		ww = new JLabel();
		txtWorkExp = new JTextField();
		a = new JLabel();
		txtPassword = new JPasswordField();
		qq = new JLabel();
		txtBirthday = new JTextField();
		o = new JLabel();
		cbxRoles = new JComboBox();
		w = new JLabel();
		txtEmpName = new JTextField();
		ss = new JLabel();
		txtCurrentLocation = new JTextField();
		y = new JLabel();
		txtAddress = new JTextField();
		aa = new JLabel();
		txtCurrentProject = new JTextField();
		d = new JLabel();
		txtPhone = new JTextField();
		g = new JLabel();
		txtCurrentDepartment = new JTextField();
		q = new JLabel();
		txtEmail = new JTextField();
		sss = new JLabel();
		txtAllowance = new JTextField();
		panel2 = new JPanel();
		btWrite = new JButton();
		btAdd = new JButton();
		btEdit = new JButton();
		btDelete = new JButton();
		btExit = new JButton();

		//======== this ========
		setLayout(new BorderLayout());

		//======== scrollPane1 ========
		{
			scrollPane1.setViewportView(tblListEmployee);
		}
		add(scrollPane1, BorderLayout.CENTER);

		//======== panel1 ========
		{
			panel1.setBorder(new TitledBorder("Employee Information"));
			panel1.setLayout(new GridBagLayout());
			((GridBagLayout)panel1.getLayout()).columnWidths = new int[] {92, 0, 0, 0, 0, 0, 0, 59, 116, 0, 0, 0, 0, 0, 6, 34, 0};
			((GridBagLayout)panel1.getLayout()).rowHeights = new int[] {0, 26, 59, 0, 0, 0, 0, 0};
			((GridBagLayout)panel1.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
			((GridBagLayout)panel1.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

			//---- s ----
			s.setText("EmpNumber");
			panel1.add(s, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtEmpNumber, new GridBagConstraints(1, 0, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- ww ----
			ww.setText("WorkExp");
			panel1.add(ww, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtWorkExp, new GridBagConstraints(9, 0, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- a ----
			a.setText("Password");
			panel1.add(a, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtPassword, new GridBagConstraints(1, 1, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- qq ----
			qq.setText("Birthday");
			panel1.add(qq, new GridBagConstraints(8, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtBirthday, new GridBagConstraints(9, 1, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- o ----
			o.setText("Roles");
			panel1.add(o, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(cbxRoles, new GridBagConstraints(1, 2, 5, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- w ----
			w.setText("EmpName");
			panel1.add(w, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtEmpName, new GridBagConstraints(1, 3, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- ss ----
			ss.setText("CurrentLocation");
			panel1.add(ss, new GridBagConstraints(8, 3, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtCurrentLocation, new GridBagConstraints(9, 3, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- y ----
			y.setText("Address");
			panel1.add(y, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtAddress, new GridBagConstraints(1, 4, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- aa ----
			aa.setText("CurrentProject");
			panel1.add(aa, new GridBagConstraints(8, 4, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtCurrentProject, new GridBagConstraints(9, 4, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- d ----
			d.setText("Phone");
			panel1.add(d, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtPhone, new GridBagConstraints(1, 5, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- g ----
			g.setText("CurrentDepartment");
			panel1.add(g, new GridBagConstraints(8, 5, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));
			panel1.add(txtCurrentDepartment, new GridBagConstraints(9, 5, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- q ----
			q.setText("Email");
			panel1.add(q, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 0, 5), 0, 0));
			panel1.add(txtEmail, new GridBagConstraints(1, 6, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 5), 0, 0));

			//---- sss ----
			sss.setText("Allowance");
			panel1.add(sss, new GridBagConstraints(8, 6, 1, 1, 0.0, 0.0,
				GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 0, 5), 0, 0));
			panel1.add(txtAllowance, new GridBagConstraints(9, 6, 7, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
		}
		add(panel1, BorderLayout.NORTH);

		//======== panel2 ========
		{
			panel2.setLayout(new FlowLayout());

			//---- btWrite ----
			btWrite.setText("Write");
			panel2.add(btWrite);

			//---- btAdd ----
			btAdd.setText("Add");
			panel2.add(btAdd);

			//---- btEdit ----
			btEdit.setText("Edit");
			panel2.add(btEdit);

			//---- btDelete ----
			btDelete.setText("Delete");
			panel2.add(btDelete);

			//---- btExit ----
			btExit.setText("Exit");
			panel2.add(btExit);
		}
		add(panel2, BorderLayout.SOUTH);
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JScrollPane scrollPane1;
	private JTable tblListEmployee;
	private JPanel panel1;
	private JLabel s;
	private JTextField txtEmpNumber;
	private JLabel ww;
	private JTextField txtWorkExp;
	private JLabel a;
	private JPasswordField txtPassword;
	private JLabel qq;
	private JTextField txtBirthday;
	private JLabel o;
	private JComboBox cbxRoles;
	private JLabel w;
	private JTextField txtEmpName;
	private JLabel ss;
	private JTextField txtCurrentLocation;
	private JLabel y;
	private JTextField txtAddress;
	private JLabel aa;
	private JTextField txtCurrentProject;
	private JLabel d;
	private JTextField txtPhone;
	private JLabel g;
	private JTextField txtCurrentDepartment;
	private JLabel q;
	private JTextField txtEmail;
	private JLabel sss;
	private JTextField txtAllowance;
	private JPanel panel2;
	private JButton btWrite;
	private JButton btAdd;
	private JButton btEdit;
	private JButton btDelete;
	private JButton btExit;
	// JFormDesigner - End of variables declaration  //GEN-END:variables

	public void setModel(TableModel model) {
		this.tblListEmployee.setModel(model);
	}

	public void doAdd(ActionListener listener) {
		this.btAdd.addActionListener(listener);
	}

	public void doEdit(ActionListener listener) {
		this.btEdit.addActionListener(listener);
	}

	public void doDelete(ActionListener listener) {
		this.btDelete.addActionListener(listener);
	}
	
	public void doWrite(ActionListener listener){
		this.btWrite.addActionListener(listener);
	}
	
	public int getSelectedItem() {
		return this.tblListEmployee.getSelectedRow();
	}

	public void setEnableControl(boolean enabled) {
		this.txtEmpNumber.setEnabled(enabled);
		this.txtPassword.setEnabled(enabled);
		this.txtAddress.setEnabled(enabled);
		this.txtAllowance.setEnabled(enabled);
		this.txtBirthday.setEnabled(enabled);
		this.txtCurrentDepartment.setEnabled(enabled);
		this.txtCurrentLocation.setEnabled(enabled);
		this.txtEmail.setEnabled(enabled);
		this.txtEmpName.setEnabled(enabled);
		this.txtPhone.setEnabled(enabled);
		this.cbxRoles.setEnabled(enabled);
		this.txtWorkExp.setEnabled(enabled);
		this.txtCurrentProject.setEnabled(enabled);
		
		
	}

	public Employee getData() {
		return new Employee(
				this.txtEmpNumber.getText(),
				this.txtPassword.getPassword().toString(),
				this.txtEmpName.getText(),
				this.cbxRoles.getSelectedItem().toString(),
				this.txtPhone.getText(),
				this.txtAddress.getText(),
				this.txtEmail.getText(),
				this.txtWorkExp.getText(),
				this.txtBirthday.getText(),
				this.txtCurrentProject.getText(),
				this.txtCurrentDepartment.getText(),
				this.txtCurrentLocation.getText(),				
				this.txtAllowance.getText()															
		);
	}

	public void display(Employee employee) {
		this.txtEmpNumber.setText(employee.getEmpNumber());
		this.txtPassword.setText(employee.getPassword());
		this.txtEmpName.setText(employee.getEmpName());
		this.cbxRoles.addItem(employee.getRoles());
		this.txtAddress.setText(employee.getAddress());
		this.txtPhone.setText(employee.getPhone());
		this.txtEmail.setText(employee.getEmail());
		this.txtWorkExp.setText(employee.getWorkExp());			
		this.txtBirthday.setText(employee.getBirthday());
		this.txtCurrentLocation.setText(employee.getCurrentLocation());
		this.txtCurrentDepartment.setText(employee.getCurrentDepartment());		
		this.txtCurrentProject.setText(employee.getCurrentProject());
		this.txtAllowance.setText(employee.getAllowance());		
	}

	public void doSelectTable(MouseAdapter mouseListener) {
		this.tblListEmployee.addMouseListener(mouseListener);
	}

	public void doSelectTable(KeyAdapter keyListener) {
		this.tblListEmployee.addKeyListener(keyListener);
	}
}
